import { createRouter, createWebHistory } from 'vue-router';
import Layout from '@/views/base/layout/index.vue';

/**
 * 公共路由表
 */
const publicRoutes = [
  {
    path: '/redirect',
    component: Layout,
    children: [
      {
        name: 'Redirect',
        path: '/redirect/:path(.*)',
        component: () => import('@/views/base/redirect.vue'),
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/welcome',
    meta: {
      isRoot: true,
    },
    children: [
      {
        path: '/welcome',
        name: 'Welcome',
        component: () => import('@/views/base/welcome.vue'),
        meta: {
          isMenu: true,
          title: '首页',
          icon: 'ep:home-filled',
        },
      },
      {
        path: '/menu1',
        meta: {
          isMenu: true,
          title: '菜单1',
          icon: 'ep:set-up',
        },
        children: [
          {
            path: '/menu1-1',
            component: () => import('@/views/base/test-page/page1.vue'),
            meta: {
              isMenu: true,
              title: '菜单1-1',
              icon: 'ep:set-up',
            },
          },
        ],
      },
      {
        path: '/menu2',
        meta: {
          isMenu: true,
          title: '菜单2',
          icon: 'ep:set-up',
        },
        children: [
          {
            path: '/menu2-1',

            meta: {
              isMenu: true,
              title: '菜单2-1',
              icon: 'ep:set-up',
            },
            children: [
              {
                path: '/menu2-1-1',
                component: () => import('@/views/base/test-page/page2.vue'),
                meta: {
                  isMenu: true,
                  title: '菜单2-1-1',
                  icon: 'ep:set-up',
                },
              },
            ],
          },
        ],
      },
      {
        path: '/404',
        name: '404',
        component: () => import('@/views/base/404.vue'),
        meta: {
          title: '404',
        },
      },
    ],
  },
];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL), // 该值在vite中配置
  routes: [...publicRoutes, { path: '/:pathMatch(.*)*', redirect: '/404' }],
});

export default router;
